﻿package com._public._filters 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.IBitmapDrawable;
	import flash.display.Shape;
	import flash.geom.Matrix;
	import flash.display.GradientType;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author 咸鱼(www.shch8.com)
	 */
	public class chxFilter 
	{
		//绘制倒影(target:目标对象必,透明度(0~1),高度(0~255))
		public static function createRef(target:DisplayObject,alpha:Number = 0.6,hei:Number = 120):Bitmap {
			//对源显示对象做上下反转处理
			var bd:BitmapData = new BitmapData(target.width, target.height, true, 0);
			var mtx:Matrix = new Matrix();
			mtx.d = -1;
			mtx.ty = bd.height;
			bd.draw(target, mtx);
			//生成一个渐变遮罩 
			var width:int=bd.width;
			var height:int =bd.height;
			mtx=new Matrix();
			mtx.createGradientBox(width,height,0.5 * Math.PI);
			var shape:Shape = new Shape();
			shape.graphics.beginGradientFill(GradientType.LINEAR,[0,0],[alpha,0],[0,hei],mtx);
			shape.graphics.drawRect(0,0,width,height);
			shape.graphics.endFill();
			var mask_bd:BitmapData=new BitmapData(width,height,true,0);
			mask_bd.draw(shape);
			bd.copyPixels(bd,bd.rect,new Point(0,0),mask_bd,new Point(0,0),false);
			//将倒影位图放在源显示对象下面 
			var ref:Bitmap=new Bitmap();
			ref.y=target.height;
			ref.bitmapData = bd;
			return ref;
		}
		
	}
	
}